package com.woniu.controller.healthSystem;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.woniu.model.gh.common.Result;
import com.woniu.model.healthSystem.dto.RolePermissionDto;
import com.woniu.model.healthSystem.entity.RolePermission;
import com.woniu.service.healthSystem.IRolePermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 角色对应权限表 前端控制器
 * </p>
 *
 * @author gb
 * @since 2023-10-19
 */
@RestController
@RequestMapping("/rolePermission")
public class RolePermissionController {

    @Autowired
    private IRolePermissionService rolePermissionService;

    @GetMapping("/findPermissionIdsByRoleId/{roleId}")
    public Result findPermissionIdsByRoleId(@PathVariable("roleId") Long roleId) {
        Wrapper<RolePermission> wrapper = Wrappers.lambdaQuery(RolePermission.class).eq(RolePermission::getRoleId,roleId);
        List<RolePermission> list = rolePermissionService.list();
        List<Long> result = list.stream().map(RolePermission::getPermissionId).collect(Collectors.toList());
        return Result.ok(result);
    }

    @PostMapping("/roleAuthorization")
    public Result roleAuthorization(@RequestBody RolePermissionDto rolePermissionDto) {
        rolePermissionService.roleAuthorization(rolePermissionDto);
        return Result.ok();
    }

}
